/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tree;

/**
 * Vnitrni forma: promenna.
 */
public class VariableTree extends VyrazTree implements Cloneable {

    private String name;
    private Type type;

    /**
     * Slot, v nemz je tato promenna.
     */
    private int slot;

    public VariableTree(Position start, Position end, String name) {
        super(start, end);
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        if(this.type==Type.STRING){
            
        }else{
            this.type=type;
        }
    }

    public int getSlot() {
        return slot;
    }

    public void setSlot(int slot) {
        this.slot = slot;
    }

    @Override
    public void accept(TreeVisitor visitor) {
        visitor.visitVariable(this);
    }

    @Override
    public void generate(Context ctx) {
        // tato metoda by se nemela nikdy zavolat
        assert false;
    }

    @Override
    public String toString() {
        return String.format("Variable %s: [%s, %s, %d]", super.toString(), name, type, slot);
    }
    
    @Override
    public VariableTree clone(){
        VariableTree v=new VariableTree(this.start, this.end, this.name);
        v.setType(this.getType());
        v.setSlot(this.getSlot());
        return v;
    }
    
}